﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class admin_Column_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AdminCs.CheckLoginState();
        if (!this.IsPostBack)
        {
            dd();
        }
    }

    private void dd()
    {
        SqlConnection con = Class1.DBconnection();
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Class where Menu_Level=1", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        DataList1.DataSource = sdr;
        DataList1.DataKeyField = "Menu_ID";
        DataList1.DataBind();
        con.Close();
        con.Dispose();
        cmd.Dispose();
        sdr.Close();
        sdr.Dispose();
    }

    protected void DataList1_DataBinding(object sender, DataListItemEventArgs e)
    {
        DataList DataList2 = (DataList)e.Item.FindControl("DataList2");

        Label l = (Label)e.Item.FindControl("L");
        SqlConnection con2 = Class1.DBconnection();
        con2.Open();
        SqlCommand cmd2 = new SqlCommand("select * from Class where  Menu_ParentLevel=" + this.DataList1.DataKeys[e.Item.ItemIndex].ToString() + "", con2);
        SqlDataReader sdr2 = cmd2.ExecuteReader();
        DataList2.DataSource = sdr2;
        DataList2.DataKeyField = "Menu_ID";
        DataList2.DataBind();
        sdr2.Close();
        sdr2.Dispose();
        con2.Close();
        con2.Dispose();
        cmd2.Dispose();
    }
    protected void DataList2_DataBinding(object sender, DataListItemEventArgs e)
    {

        DataList DataList3 = (DataList)e.Item.FindControl("DataList3");
        Label la = (Label)e.Item.FindControl("Label1");
        string typeID = la.Text.ToString();

        SqlConnection con3 = Class1.DBconnection();
        con3.Open();
        SqlCommand cmd3 = new SqlCommand("select * from Class where Menu_ParentLevel='" + typeID + "'", con3);
        SqlDataReader sdr3 = cmd3.ExecuteReader();
        DataList3.DataSource = sdr3;
        DataList3.DataBind();
        con3.Close();
        con3.Dispose();
        cmd3.Dispose();
        sdr3.Close();
        sdr3.Dispose();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int Menu_L = 1;
        int Menu_ParentLevel = 0;
        int Menu_Lock = 0;
        string Menu_B = TextBox1.Text.Trim();
        if (Menu_B == "")
        {
            Response.Write("<script>alert('请输入分类名称！！');history.go(-1);</script>");
        }
        else
        {
            string sqlstr2 = "insert into Class(Menu_Name,Menu_Level,Menu_ParentLevel,Menu_Lock)values('" + Menu_B + "','" + Menu_L + "','" + Menu_ParentLevel + "','" + Menu_Lock + "')";
            Class1.ExecSql(sqlstr2);
            Response.Write("<script language=javascript>alert('添加成功！');window.location='Column_Manage.aspx';</script>");
        }
    }
}
